<extend file='../master'/>
<block name="content">
    <div>
        <button class="btn btn-success" onclick="upImage(this)">选择图片</button>
    </div>
    <br/>
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title">图片列表</h3>
        </div>

        <div class="panel-body">
            <ul>
                <style>
                    *{margin: 0;padding: 0;}
                    li{list-style: none;}
                    li img{border: solid 1px #cccc77;width: 200px;height: 140px;margin-right: 10px;}
                </style>
                <foreach from="$data" value="$d">
                    <li style="float:left;">
                        <img src="{{$d['path']}}" style="width: 200px;">
                    </li>
                </foreach>
            </ul>
        </div>
    </div>
</block>

<script>
    //上传图片
    function upImage(obj) {
        require(['util'], function (util) {
            util.image(function (images) {
                $.post('{{site_url("site/pushImage")}}', {file: images[0]}, function (res) {
                    if (res.valid == 1) {
                        util.message('上传成功', 'refresh', 'success');
                    } else {
                        util.message('上传失败,请检测文件大小', '', 'error');
                    }
                })
            }, [])
        });
    }
    //移除图片 
    function removeImg(obj) {
        $(obj).prev('img').attr('src', 'resource/images/nopic.jpg');
        $(obj).parent().prev().find('input').val('');
    }
</script>
